package com.lwlk.zdk.controller.Supervise;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lwlk.zdk.enums.RetCode;
import com.lwlk.zdk.mapper.T.*;
import com.lwlk.zdk.mapper.pw.pwUserMapper;
import com.lwlk.zdk.model.*;
import com.lwlk.zdk.model.T.TRegion;
import com.lwlk.zdk.model.pw.pwDriver;
import com.lwlk.zdk.model.pw.pwPlatformAttention;
import com.lwlk.zdk.model.sys.sysUser;
import com.lwlk.zdk.model.T.TDisVehicle;
import com.lwlk.zdk.service.CarService.CarService;
import com.lwlk.zdk.service.User.SysUserService;
import com.lwlk.zdk.util.*;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.NumberFormat;
import java.util.*;
/*
* 车辆监管:地图左侧车辆信息
* */

@RestController
@Transactional
@RequestMapping(value = "/Map")
public class MapVehicleController {

    private final static String port = PropUtils.getString("ports");
    private final static String Ip = PropUtils.getString("Ip");
    private final static String clientCode = PropUtils.getString("clientCode");
    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    CarService carService;
    @Autowired
    TDisEnterpriseMapper tDisEnterpriseMapper;
    @Autowired
    TDisPlatformMapper tDisPlatformMapper;
    @Autowired
    TDisVehicleMapper tDisVehicleMapper;
    @Autowired
    TRegionMapper regionMapper;
    @Autowired
    TDisDictionaryMapper tDisDictionaryMapper;
    @Autowired
    TDisDictionaryMapper disDictionaryMapper;
    @Autowired
    pwUserMapper pwUserMapper;


    //============根据平台id查询下级平台和下级的业户车辆=====================-------------未完成
    @RequestMapping(value = "/show",method = RequestMethod.POST)
    public Response getVehicle(Integer platformIds){
        Response response=new Response();
        try {
            List<Map<String,Object>>userAndVehicle =tDisPlatformMapper.selectAll(platformIds);
            response.setData(userAndVehicle);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;

    }


    @ApiOperation(value = "车辆所属平台信息展示")
    @RequestMapping(value = "/platformMessage",method = RequestMethod.GET)
    public Response getPlatformMessage(Integer vehicleId){
      Response response=new Response();
      try {
          List<sysUser> platformMessage=tDisPlatformMapper.selectPlatformMessage(vehicleId);
          response.setData(platformMessage);
          response.setCode(RetCode.SUCCESS);
          response.setMsg("执行成功");
      }catch (Exception e){
          e.printStackTrace();
      }
      return  response;
    }


    @ApiOperation(value = "车辆信息展示")
    @RequestMapping(value = "/vehicleMessage",method = RequestMethod.POST)
    public Response getVehicleMessage(String vehicleNumber){
        Response response=new Response();
        try {
            List<TDisVehicle>pwVehicleList=tDisVehicleMapper.selectVehicleMessage(vehicleNumber);
            response.setData(pwVehicleList);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }

    @ApiOperation(value = "人员信息展示")
    @RequestMapping(value = "/personMessage",method = RequestMethod.POST)
    public Response getPersonMessage(String vehicleNumber){
        Response response=new Response();
        try {
            pwDriver pwDriver=carService.selectDriverMessage(vehicleNumber);
            response.setData(pwDriver);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }

    @ApiOperation(value = "车辆所属企业信息")
    @RequestMapping(value = "/enterpriseMessage",method = RequestMethod.POST)
    public Response getEnterpriseMessage(String vehicleNumber){
        Response response=new Response();
        try {
             List<Map<String,Object>>enterpriseMessage=tDisEnterpriseMapper.selectEnterpriseMessage(vehicleNumber);
             response.setData(enterpriseMessage);
             response.setData(RetCode.SUCCESS);
             response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }


    @ApiOperation(value = "平台关注列表")
    @RequestMapping(value = "/platformAttention",method = RequestMethod.GET)
    public Response getPlatformAttention(Integer platformId){
        Response response=new Response();
        try {
            List<pwPlatformAttention>pwPlatformAttentionList=carService.selectPlatformAttention(platformId);
            response.setData(pwPlatformAttentionList);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }

    @ApiOperation(value = "平台关注列表添加车牌号")
    @RequestMapping(value = "/platformAttentionAdd",method = RequestMethod.POST)
    public Response getPlatformAttentionAdd(Integer platformId, String vehicleNumber, Integer vId, String sim, HttpServletRequest request){
        Response response=new Response();
        try {
            Boolean flag=listerUtil.getRoleType(request);
            if (flag==false){
                response.setCode(RetCode.ACCOUNT_EXIST);
                response.setMsg("此账号为监管员账号,不可进行操作");
                return response;
            }
            int count=carService.selectByVehicleId(vId);
            if (count>0){
                response.setCode(RetCode.ACCOUNT_EXIST);
                response.setMsg("此车牌号已存在,请重新添加");
                return response;
            }
            int i=carService.platformAttentionAdd(platformId,vehicleNumber,vId,sim);
            response.setData(i);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }


    @ApiOperation(value = "平台关注列表删除车牌号")
    @RequestMapping(value = "/platformAttentionDelete",method = RequestMethod.POST)
    public Response getPlatformAttentionDelete(Integer id,HttpServletRequest request){
        Response response=new Response();
        try {
            Boolean flag=listerUtil.getRoleType(request);
            if (flag==false){
                response.setCode(RetCode.ACCOUNT_EXIST);
                response.setMsg("此账号为监管员账号,不可进行操作");
                return response;
            }
            Boolean flage=listerUtil.getLevel(request);
            int i=carService.platformAttentionDelete(id);
            response.setData(i);
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return response;
    }


    @ApiOperation(value = "根据在线状态和车辆所属行业进行查询")
    @RequestMapping(value = "/searchChoice",method = RequestMethod.POST)
    public Response getSearchChoice(String isOnline,String industry,String VehicleNumberOrEnterprise){
     Response response=new Response();
     try {
         //根据车牌或业户
         if (VehicleNumberOrEnterprise.equals(null)){
            //查询是否在线
             if (!industry.equals(null)){
                 //查询车辆在线或离线所属行业的车辆
                 List<Map<String,Object>>VehicleIndustry=carService.selectVehicleIndustryAndIndustry(isOnline,industry);//----mapper的sql没写             }else {
             }else {
                 //查询车辆所属行业的车辆
                 List<Map<String,Object>>VehicleIndustry=carService.selectVehicleIndustry(industry);
             }
         }else {
             //
         }



     }catch (Exception e){
         e.printStackTrace();
     }

     return response;
    }




    /*
    * regionCode:行政区划代码
    *industryCodeList:行业编码，多个行业以逗号分隔
    * */
    /*@ApiOperation(value = "车辆监管-左侧树-拉取直接下级行政区划及其在线车辆数和车辆总数")
    @RequestMapping(value = "/regiontree",method = RequestMethod.GET)
    public JSONObject getRegionTree(String regionCode){
       Map map=new HashMap();
       map.put("regionCode",regionCode);//必选 行政区划代码
       String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/regiontree";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String result = HttpClientUtils.doGet(url,headMap, map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }*/


    @ApiOperation(value = "车辆监管-左侧树-在线数、离线数、报警数")
    @RequestMapping(value = "/onlineofflinewarn",method = RequestMethod.GET)
    public JSONObject onlineofflinewarn(String regionCode,String industryIds){
        Map map=new HashMap();
        map.put("regionCode",regionCode);//必选 登录用户所属机构所在地的行政区划代码
        map.put("industryIds",industryIds);//车辆所属行业，多个行业以英文逗号分隔
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/onlineofflinewarn";
        String result = HttpClientUtils.doGet(url,headMap, map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "车辆树使用，查询车辆在线状态")
    @RequestMapping(value = "/onlinestatus",method = RequestMethod.GET)
    public JSONObject onlinestatus(String vids){
        Map map=new HashMap();
        map.put("vids",vids);//必选 车辆所属行业，多个行业以英文逗号分隔
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/onlinestatus";
        String result = HttpClientUtils.doGet(url,headMap, map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        Integer vid=Integer.parseInt(jo.getString("vid"));
        //String vehicleNumber=pwVehicleMapper.selectByVid(vId);//车辆名称
        String vehicleNumber=tDisVehicleMapper.selectByVid(vid);
        json.put("vehicleNumber",vehicleNumber);
        return json;
    }



    @ApiOperation(value = "车辆监管-左侧树-以县级区划为单位拉取车辆列表(包含每辆车在线离线状态)--废弃")
    @RequestMapping(value = "/countyVehicletree",method = RequestMethod.GET)
    public JSONObject getCountyVehicletree(String onlineStatus,String enterpriseName,String vno,String inOutFlag,String industryId,String regionCode){
        Map map=new HashMap();
        map.put("onlineStatus",onlineStatus);
        map.put("enterpriseName",enterpriseName);
        map.put("vno",vno);
        map.put("inOutFlag",inOutFlag);
        map.put("industryId",industryId);
        map.put("regionCode",regionCode);//必选 县级行政区划代码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/vehicletree";
        String result = HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }

    @ApiOperation(value = "首页入网率和上线率")
    @RequestMapping(value = "/getNetAndOnlineRate",method = RequestMethod.GET)
    public JSONObject getNetAndOnlineRate(String admdivcode){
        Map map=new HashMap();
        map.put("admdivcode",admdivcode);//必传 登录用户所属的行政区划代码
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/assessment/cityCounty/getNetAndOnlineRate";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("result");
        NumberFormat nf = java.text.NumberFormat.getPercentInstance();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            String netRate=jsonObject.getString("netRate");//入网率
            String onlineRate=jsonObject.getString("onlineRate");//上线率
            String areaCode=jsonObject.getString("admdivcode");//地区码
            double net=Double.valueOf(netRate);
            double online=Double.valueOf(onlineRate);
            String onlineRates=nf.format(online);//将上线率转成百分数
            String netRates=nf.format(net);//将入网率转成百分数
            String areaCodeName=regionMapper.selectAreaCodeName(Integer.parseInt(areaCode));
            jsonObject.put("onlineRate",onlineRates);
            jsonObject.put("netRate",netRates);
            jsonObject.put("areaCodeName",areaCodeName);
        }
        return json;
    }


    @ApiOperation(value = "首页-登录用户管辖地区入网率、当月上线率、实时在线车辆数、出域车辆数、入域车辆数查询接口")
    @RequestMapping(value = "/rate",method = RequestMethod.GET)
    public JSONObject getRate(Integer regionId,String AreaCode){
        Map map=new HashMap();
        map.put("regionId",regionId);//行政区划id
        map.put("regionCode",AreaCode);//必传 登录用户所属的行政区划代码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/rate";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }

    @ApiOperation(value = "车辆监管-左侧树-拉取域内直接下级行政区划、业户及其在线车辆数和车辆总数，后追加驾驶员相关记录（只包括域内）；域外相关行政区划及其在线车辆数和车辆总数。域内域外分别提供")
    @RequestMapping(value = "/regiontree",method = RequestMethod.GET)
    public JSONObject getRegiontree(String regionCode,String inOut,String userId,String type,String industryId){
       Map map=new HashMap();
       map.put("regionCode",regionCode);
       map.put("in_out",inOut);
       map.put("userId",userId);
       map.put("type",type);
       map.put("industryId",industryId);
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
       Map<String,String>headMap=new HashMap<>();
       headMap.put("clientCode",clientCode);
       String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/regiontree";
       String result= HttpClientUtils.doGet(url,headMap,map);
       JSONObject json= JSONObject.parseObject(result).getJSONObject("result");
       JSONArray jsonArray=new JSONArray();
        if (inOut.equals("0")){
            jsonArray=json.getJSONArray("innerEnterprise");
       }else {
            jsonArray=json.getJSONArray("outerProvince");
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
       /*     String eid= jsonObject.getString("id").replaceAll("e_","");//企业id
            jsonObject.put("id",eid);*/
        }
        return json;
    }

    @ApiOperation(value = "车辆监管-左侧树-以县级区划为单位拉取车辆列表（包含每辆车在线离线状态）")
    @RequestMapping(value = "/vehicletree",method = RequestMethod.GET)
    public JSONObject getVehicletree(String regionCode,String onlineStatus,String enterpriseName,String vno,String inOut,String industryId,String level,String parentId){
/*        if (parentId==null){
            String list="{\"code\":9001,\"msg\":\"请根据域内或域外的车辆查询\",\"result\":{}}";
            return JSONObject.parseObject(list);
        }*/
        Map map=new HashMap();
        map.put("regionCode",regionCode);//必传 县级行政区划代码
        map.put("onlineStatus",onlineStatus);//在线状态，0离线，1在线
        map.put("enterpriseName",enterpriseName);//企业名称
        map.put("vno",vno);//车牌号
        map.put("inOutFlag",inOut);//域内(0)、域外(1)
        map.put("industryId",industryId);//行业类型（两客一危、货运、其他）
        map.put("level",level);//必传 用户登录区域级别（1省、2市、3县）
        map.put("parentId",parentId);// 上级编码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/vehicletree";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("result");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer regionId= Integer.valueOf(jsonObject.getString("regionCode"));//地区码
            String eid= jsonObject.getString("eid");//企业id
            String enterpriseId=eid.replace("e_","");
            String eName=tDisEnterpriseMapper.selectByEid(Integer.valueOf(enterpriseId));//业户名称
            List<Map<String,Object>>regionNameList=regionMapper.selectRank(regionId);
            if (regionNameList.size()==0){
                jsonObject.put("province",null);//省
                jsonObject.put("city",null);//市
                jsonObject.put("county",null);//区县
                jsonObject.put("enterpriseName",eName);
            }else {
                jsonObject.put("province",regionNameList.get(0).get("province"));//省
                jsonObject.put("city",regionNameList.get(0).get("city"));//市
                jsonObject.put("county",regionNameList.get(0).get("county"));//区县
                jsonObject.put("enterpriseName",eName);
            }

        }
        return json;
    }


    @ApiOperation(value = "车辆监管-左侧树-查询车牌号")
    @RequestMapping(value = "/showVehicletree",method = RequestMethod.GET)
    public List<CommonAreaModel> getShowVehicleTree(String regionCode, String onlineStatus, String enterpriseName, String vno, String inOut, String industryId, String level, String parentId,String userId,String type){
        List<CommonAreaModel> regionList=regionMapper.selectArea(37);
        List<CommonAreaModel> totallist = new ArrayList<>();
        Map<Integer, CommonAreaModel> areaMap = new HashMap<>();

        for(int i = 0;i<regionList.size();i++){
            areaMap.put(regionList.get(i).getCode(), regionList.get(i));
        }

        Map map=new HashMap();
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        //查询车辆时,不选行业id,先查询vehicletree接口
            map.put("regionCode",regionCode);//必传 县级行政区划代码
            map.put("onlineStatus",onlineStatus);//在线状态，0离线，1在线
            map.put("enterpriseName",enterpriseName);//企业名称
            if (vno!=null) {
                String vehicleNumber = vno.toUpperCase();
                map.put("vno", vno.toUpperCase());//车牌号
            }else {
                map.put("vno",vno);//车牌号
            }
            map.put("inOutFlag",inOut);//域内(0)、域外(1)
            map.put("industryId",industryId);//行业类型（两客一危、货运、其他）
            map.put("level",level);//必传 用户登录区域级别（1省、2市、3县）
            map.put("parentId",parentId);// 上级编码
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            String url="http://"+Ip+":"+port+"/dis/v1/vehicle/realtime/vehicletreeByNumber";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONArray jsonArray=json.getJSONArray("result");

            JSONArray tarray = new JSONArray();
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                // 获取地区编码
                String rCode = jsonObject.getString("regionCode");
                //获取市级编码
                Integer newCode = Integer.valueOf(rCode)/100*100;
                // 获取车牌号
                String name = jsonObject.getString("vno");
                // 获取业户id
                String eid = jsonObject.getString("eid");
                String showInfo= jsonObject.getString("showInfo");
                if(!StringUtils.isEmpty(showInfo)) {
                    String names = showInfo.replace(name, "").replace("(", "").replace(")", "");
                    String[] strs = names.split("\\/");
                    if(strs.length > 0) {
                        String ename = strs[0];
                        if(areaMap.containsKey(newCode)){
                            if(areaMap.get(newCode).getMap() == null){
                                areaMap.get(newCode).setMap(new HashMap<String, CommonEnterpriseModel>());
                            }
                            if(!areaMap.get(newCode).getMap().containsKey(eid)){
                                areaMap.get(newCode).getMap().put(eid, new CommonEnterpriseModel());
                                areaMap.get(newCode).getMap().get(eid).setEid(eid);
                                areaMap.get(newCode).getMap().get(eid).setTitle(ename);
                                areaMap.get(newCode).getMap().get(eid).setRegionCode(rCode);
                                areaMap.get(newCode).getMap().get(eid).setList(new ArrayList<CommonModel>());
                                areaMap.get(newCode).getMap().get(eid).setChildren(new ArrayList<JSONObject>());
                            }
                            jsonObject.put("title",name);
                            jsonObject.put("status","3");
                            areaMap.get(newCode).getMap().get(eid).getChildren().add(jsonObject);
                        }
                    }
                }
            }
            for(Integer key : areaMap.keySet()){
                if(areaMap.get(key).getMap() != null && areaMap.get(key).getMap().size() != 0){
                    areaMap.get(key).setChildren(new ArrayList(areaMap.get(key).getMap().values()));
                    areaMap.get(key).setMap(new HashMap<>());
                    totallist.add(areaMap.get(key));
                }
            }
        for (int i = 0; i < totallist.size(); i++) {
            //根据地区编码行业类型车牌号查询此地区所有的符合条件的车辆数
            long start1,end1;
            start1 = System.currentTimeMillis();
            if (industryId!=null){
                String[] industry=industryId.split(",");
                //行业id的list
                List<Integer> resultList = new ArrayList<>(industry.length);
                for (String s : industry) {
                    resultList.add(Integer.valueOf(s));
                }
                Integer vehicleAll=0;
                Integer onlineVehicle=0;
                Integer offVehicle=0;
                String number=null;
                Integer code=totallist.get(i).getCode();
                code=Integer.parseInt(code.toString().substring(0,4));
                long start,end;
                start = System.currentTimeMillis();
                if (vno!=null){
                    vno=vno.toUpperCase();
                }
                List<VehicleNumber> vehicleNumber=tDisVehicleMapper.selectAllVehicle(code,vno,resultList);
                end = System.currentTimeMillis();
                logger.info("开始时间:" + start+ "; 结束时间:" + end+ "; 语句执行了:" + (end - start) + "(ms)");
                for (int j = 0; j < vehicleNumber.size(); j++) {
                    vehicleAll+=vehicleAll+vehicleNumber.get(j).getAllNumber();
                    onlineVehicle+=onlineVehicle+vehicleNumber.get(j).getOnlineNumber();
                    offVehicle=vehicleAll-onlineVehicle;
                }
                //在线状态为离线
                if (onlineStatus==null){
                    number="("+vehicleAll+"/"+vehicleAll+")";
                }else {
                    if (onlineStatus.equals("0")){
                        number="("+offVehicle+"/"+vehicleAll+")";
                    }else if (onlineStatus.equals("1")){//在线状态为在线
                        number="("+onlineVehicle+"/"+vehicleAll+")";
                    }
                }
                totallist.get(i).setTitle(totallist.get(i).getTitle()+number);
            }else {
                Integer vehicleAll=0;
                Integer onlineVehicle=0;
                Integer offVehicle=0;
                String number=null;
                Integer code=totallist.get(i).getCode();
                code=Integer.parseInt(code.toString().substring(0,4));
                long start,end;
                start = System.currentTimeMillis();
                if (vno!=null){
                    vno=vno.toUpperCase();
                }
                List<VehicleNumber> vehicleNumber=tDisVehicleMapper.selectAllVehicle(code,vno,null);
                end = System.currentTimeMillis();
                logger.info("开始时间:" + start+ "; 结束时间:" + end+ "; 语句执行了:" + (end - start) + "(ms)");
                for (int j = 0; j < vehicleNumber.size(); j++) {
                    vehicleAll+=vehicleAll+vehicleNumber.get(j).getAllNumber();
                    onlineVehicle+=onlineVehicle+vehicleNumber.get(j).getOnlineNumber();
                    offVehicle=vehicleAll-onlineVehicle;
                }
                //在线状态为离线
                if (onlineStatus==null){
                    number="("+vehicleAll+"/"+vehicleAll+")";
                }else {
                    if (onlineStatus.equals("0")){
                        number="("+offVehicle+"/"+vehicleAll+")";
                    }else if (onlineStatus.equals("1")){//在线状态为在线
                        number="("+onlineVehicle+"/"+vehicleAll+")";
                    }
                }
                totallist.get(i).setTitle(totallist.get(i).getTitle()+number);
            }
            end1 = System.currentTimeMillis();
            logger.info("start time:" + start1+ "; end time:" + end1+ "; Run Time:" + (end1 - start1) + "(ms)");
        }
            return totallist;
}





    @ApiOperation(value = "下级平台断开数")
    @RequestMapping(value = "/platformBreak",method = RequestMethod.GET)
    public JSONObject getPlatformBreak(){
        Map map=new HashMap();
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/connectStatistic/platformBreak";
        String result= HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("result");
        Integer platformBreak=jsonArray.size();
        json.put("platformBreak",platformBreak);
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            String platformName=tDisPlatformMapper.selectpId(pId);
            List<Map<String,Object>>platformList=tDisPlatformMapper.selectByPrimaryKeyDetails(pId);
            jsonObject.put("platformName",platformName);
            if (platformList.size()>0){
                Integer platfornTypeId= Integer.valueOf(String.valueOf(platformList.get(0).get("platfornType")));
                String platformType=platfornTypeId==0?"地市级政府监管平台":platfornTypeId==1?"非经营性企业监控平台":platfornTypeId==2?"经营性企业监控平台":null;
                jsonObject.put("platformType",platformType);
            }else {
                jsonObject.put("platformType",null);
            }

        };
        return json;
    }


    @ApiOperation(value = "查询当日报警车辆总数，定时调用")
    @RequestMapping(value = "/getTodayWarningVehicleCount",method = RequestMethod.GET)
    public JSONObject getTodayWarningVehicleCount(String regionCode){
       Map map=new HashMap();
       map.put("regionCode",regionCode);//必传
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/getTodayWarningVehicleCount";
       String result= HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "平台监管-左侧平台树获取接口")
    @RequestMapping(value = "/tree",method = RequestMethod.GET)
    public JSONObject getTree(String regionCode){
      Map map=new HashMap();
      map.put("regionCode",regionCode);//必传 行政区划代码
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
      String url="http://"+Ip+":"+port+"/dis/v1/platform/tree";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }

    @ApiOperation(value = "平台监管-平台车辆情况")
    @RequestMapping(value = "/vehicleStatistics",method = RequestMethod.GET)
    public JSONObject getVehicleStatistics(String id,String page,String limit,String onlineStatus,String vehicleNumber,String industryId,String transCertificateCode,String eName){
        String eIdsList="";
        String eIds=null;
        if (vehicleNumber!=null && vehicleNumber.length() < 3) {
            String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
            return JSONObject.parseObject(list);
        }
        if (eName!=null && eName.equals("")==false){
            List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);

            if (eIdsLists.size()>0) {
                for (int i = 0; i < eIdsLists.size(); i++) {
                    eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id") + ",";
                }
                eIds = StringUtils.join(eIdsList.split(","), ",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        Map map=new HashMap();
        map.put("status",onlineStatus);//在线1，离线0
        if (vehicleNumber!=null){
            vehicleNumber=vehicleNumber.toUpperCase();
        }
        map.put("vehicleNumber",vehicleNumber);//车牌号
        map.put("industryId",industryId);//行业id
        map.put("transCertificateCode",transCertificateCode);//道路运输证号
        map.put("eIds",eIds);//企业id，多个逗号分隔
        map.put("page",page);//必传 页码 ，默认值1
        map.put("limit",limit);//必传 页面记录数 ，默认值10

        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/platform/"+id+"/vehicle/statistics";
        String result= HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            String vehicelColor=jsonObject.getString("vehicleLicenseColor");//车辆颜色
            onlineStatus=Integer.valueOf(jsonObject.getString("onlineStatus"))==0?"离线":Integer.valueOf(jsonObject.getString("onlineStatus"))==1?"在线":null;
            String vehicleId=jsonObject.getString("vehicleId");//车辆id
            String industry=jsonObject.getString("industryId");//行业id
            Integer pId=Integer.parseInt(jsonObject.getString("platformId"));//平台id
            Integer eId=Integer.parseInt(jsonObject.getString("enterpriseId"));//企业id
            String vehicleType=jsonObject.getString("vehicleType");//车辆类型
            String platformName=tDisPlatformMapper.selectpId(pId);//平台名称
            String vehicleTypeName=tDisDictionaryMapper.selectVehicleType(vehicleType);//车辆类型
            TDisVehicle disVehicle=tDisVehicleMapper.selectByPrimaryKey(Integer.parseInt(vehicleId));
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);//业户名称
            String vehicleLicenseColor=disDictionaryMapper.selectVehicleColor(vehicelColor);//车牌颜色
            String industryName= tDisDictionaryMapper.selectByItemValue(industry);//行业名称
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("onlineStatus",onlineStatus);
            jsonObject.put("netTime",disVehicle.getNetTime());
            jsonObject.put("industryName",industryName);
            jsonObject.put("platformName",platformName);
            jsonObject.put("vehicleLicenseColorName",vehicleLicenseColor);//车牌颜色
            jsonObject.put("vehicleTypeName",vehicleTypeName);
            jsonObject.put("enterpriseName",enterpriseName);
        }
        return json;
    }



    @ApiOperation(value = "查看某个平台的上传情况")
    @RequestMapping(value = "/uploadVehicle",method = RequestMethod.POST)
    public JSONObject getUploadVehicle(Integer platformId){
     String url="http://"+Ip+":"+port+"/dis/v1/platform/"+platformId+"/809";
       Map<String,String>headMap=new HashMap<>();
       headMap.put("clientCode",clientCode);
     String result=HttpClientUtils.doGet(url,headMap);
       JSONObject json= JSONObject.parseObject(result);
     return json;
    }


    @ApiOperation(value = "查询某个平台在线状态： 上线车辆数： 在线车辆数： 今日报警车辆数：")
    @RequestMapping(value = "/vehicle/statistic",method = RequestMethod.GET)
    public JSONObject getVehicleStatistic(Integer platformId,String regionCode,String platformType){

        List<Map<String,Object>>platform=tDisPlatformMapper.selectByPlatformId(platformId);
        Map map=new HashMap();
        map.put("regionCode",String.valueOf(platform.get(0).get("platformCode")));//必传 行政区划代码
        map.put("platformType",String.valueOf(platform.get(0).get("platformType")));//必传 平台类型,0地市级政府监管平台，1非经营性企业监控平台，2经营性企业监控平台，3货运服务监控平台
        String url="http://"+Ip+":"+port+"/dis/v1/platform/"+platformId+"/vehicle/statistic";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }



    @ApiOperation(value = "历史视频回放控制接口")
    @RequestMapping(value = "/video/playback_control",method = RequestMethod.POST)
    public JSONObject playbackControl(String param, String avitemType,String channelId,String vehicleId,String controlType,String fastTime,String tdateTime){
        Map map=new HashMap();
        map.put("param",param);
        map.put("avitemType",avitemType);//必传
        map.put("channelId",channelId);//必传 通道
        map.put("vehicleId",vehicleId);//必传 车辆id
        map.put("controlType",controlType);//必传 控制类型
        map.put("fastTime",fastTime);//必传 倍速
        map.put("tdateTime",tdateTime);//必传 拖动时间
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/video/playback_control";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "历史视频回放接口")
    @RequestMapping(value = "/video/playback",method = RequestMethod.POST)
    public JSONObject playback(String param, String playbackStarttime,String playbackEndtime,String channelId,String vehicleId,String avitemType,String alarmType,String streamType,String memType){
        Map map=new HashMap();
        map.put("param",param);
        map.put("playbackStarttime",playbackStarttime);//必传 开始时间
        map.put("playbackEndtime",playbackEndtime);//必传 结束时间
        map.put("channelId",channelId);//必传 通道
        map.put("vehicleId",vehicleId);//必传 车辆id
        map.put("avitemType",avitemType);//必传 音视频类型
        map.put("alarmType",alarmType);//必传 报警类型
        map.put("streamType",streamType);//必传 音码流类型
        map.put("memType",memType);//必传 存储器类型
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/video/playback";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "查询音视频目录请求接口")
    @RequestMapping(value = "/video/directory",method = RequestMethod.POST)
    public JSONObject directory(String param, String alarmType,String startTime,String endTime,String channelId,String vehicleId,String avitemType,String streamType,String memType){
        Map map=new HashMap();
        map.put("param",param);
        map.put("startTime",startTime);//必传 开始时间
        map.put("endTime",endTime);//必传 结束时间
        map.put("channelId",channelId);//必传 通道
        map.put("vehicleId",vehicleId);//必传 车辆id
        map.put("avitemType",avitemType);//必传 音视频类型
        map.put("alarmType",alarmType);//必传 报警类型,8个字节
        map.put("streamType",streamType);//必传 音码流类型
        map.put("memType",memType);//必传 存储器类型
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/video/playback";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }



    @ApiOperation(value = "实时音视频停止接口")
    @RequestMapping(value = "/video/realTimeStop",method = RequestMethod.POST)
    public JSONObject realTimeStop(String param, String channelId,String vehicleId,String avitemType){
        Map map=new HashMap();
        map.put("param",param);
        map.put("channelId",channelId);//必传 通道
        map.put("vehicleId",vehicleId);//必传 车辆id
        map.put("avitemType",avitemType);//必传 音视频类型
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/video/realTimeStop";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }

    @ApiOperation(value = "实时音视频请求接口")
    @RequestMapping(value = "/video/realTimeView",method = RequestMethod.POST)
    public JSONObject realTimeView(String param, String channelId,String vehicleId,String avitemType){
        Map map=new HashMap();
        map.put("param",param);
        map.put("channelId",channelId);//必传 通道
        map.put("vehicleId",vehicleId);//必传 车辆id
        map.put("avitemType",avitemType);//必传 音视频类型
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/vehicle/video/realTimeView";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }



    @ApiOperation(value = "省平台首页今日报警车辆数")
    @RequestMapping(value = "/homePageAlarmCount",method = RequestMethod.GET)
    public JSONObject homePageAlarmCount(String admdivcode){
        Map map=new HashMap();
        map.put("admdivcode",admdivcode);//必选 行政区划编码
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/statistics/vehicleAlarm/homePageAlarmCount";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }



    //================平台车辆情况查询接口===============
   /* @RequestMapping(value = "/platformVehicle",method = RequestMethod.GET)
    public Response getPlatformVehicle(Integer platformId){
        Response response=new Response();
        List list=new LinkedList();
        pwVehicle pwVehicle=new pwVehicle();
      //先查询出平台下的车辆
        List<Map<String,Object>>platformVehicleList=carService.selectPlatformVehicleAll(platformId);
        for (int i = 0; i < platformVehicleList.size(); i++) {
            Map map=platformVehicleList.get(i);
            Object vehicleId=map.get("vehicleId");//获取车辆id
            list.add(Integer.valueOf(String.valueOf(vehicleId)));
        }
       Map map=new HashMap();
       map.put("vehicleIds",list);
       map.put("id",platformId);
       String url="http://"+Ip+":"+port+"/dis/v1/platform /{id}/vehicle/statistics";
       String result=HttpClientUtil.doGet(url,map);
       JSONObject object = (JSONObject)JSONObject.parse(result);
        for (int i = 0; i < platformVehicleList.size(); i++) {
            Integer o =Integer.parseInt(String.valueOf( object.getJSONObject("data").get("vehicleId")));
            Map map1=platformVehicleList.get(i);
            Integer vehicleId=Integer.parseInt(String.valueOf(map1.get("vehicleId")));//获取车辆id
            Map map2=new HashMap();
            if (o==vehicleId){
                map2.put("onlineStatus",object.getJSONObject("data").get("onlineStatus"));
            }
            platformVehicleList.add(map2);
            response.setData(platformVehicleList);
            response.setData(RetCode.SUCCESS);
            response.setMsg("执行成功");
            return response;

        }
        return null;

    }*/


    /*
    * regionCode:行政区划代码
    * */
    @ApiOperation(value = "按行政区划查车接口")
    @RequestMapping(value = "/getVehicleByRegion",method = RequestMethod.GET)
    public JSONObject getVehicleByRegion(String startTime,String endTime,String regionCode){
        Map map=new HashMap();
        map.put("startTime",startTime);// 开始时间 yyyy-mm-dd HH:mm:ss
        map.put("endTime",endTime);// 结束时间 yyyy-mm-dd HH:mm:ss
        map.put("regionCode",regionCode);//必传 行政区划代码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/getVehicleByRegion";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("data");
        if (jsonArray==null){
            return json;
        }for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer eId=Integer.parseInt(jsonObject.getString("eid"));//企业id
            String admdivcode=jsonObject.getString("admdivcode");//企业id
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
            String admdivcodeName=regionMapper.selectByoId(Integer.valueOf(admdivcode));
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("organizationName",admdivcodeName);
        }
        return json;
    }



    @ApiOperation(value = "按省查询出域的车辆数")
    @RequestMapping(value = "/group",method = RequestMethod.GET)
    public JSONObject group(String industryIds,String regionCode){
        Map map=new HashMap();
        map.put("industryId",industryIds);//行业编码，如多个以,分隔
        map.put("regionCode",regionCode);//必传 行政区划编码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/group";
        long start1,end1;
        start1 = System.currentTimeMillis();
        String result=HttpClientUtils.doGet(url,headMap,map);
        end1 = System.currentTimeMillis();
        logger.info("start time:" + start1+ "; end time:" + end1+ "; Run Time:" + (end1 - start1) + "(ms)");
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }




    @ApiOperation(value = "按省查询入域的车辆详情")
    @RequestMapping(value = "/groupByInProvince",method = RequestMethod.GET)
    public JSONObject groupByInProvince(String industryId,String provinceId,String regionCode,String pageNum,String pageSize){
        Map map=new HashMap();
        map.put("industryId",industryId);//行业编码，如多个以,分隔
        map.put("provinceId",provinceId);//必传 省份编码
        map.put("regionCode",regionCode);//必传 行政区划编码的
        map.put("pageNum",pageNum);//必传 请求的页码
        map.put("pageSize",pageSize);//必传 分页每页的数量
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/groupByInProvince";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "按省查询出域的车辆详情")
    @RequestMapping(value = "/groupByProvince",method = RequestMethod.GET)
    public JSONObject groupByProvince(String industryId,String provinceId,String regionCode,String pageNum,String pageSize){
        Map map=new HashMap();
        map.put("industryId",industryId);//行业编码，如多个以,分隔
        map.put("provinceId",provinceId);//必传 省份编码
        map.put("regionCode",regionCode);//必传 行政区划编码的
        map.put("pageNum",pageNum);//必传 请求的页码
        map.put("pageSize",pageSize);//必传 分页每页的数量
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/groupByProvince";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    /*
    * leftUpPosition:左上角经纬度(纬度与经度用逗号分隔)
    * rightDownPosition:右下角经纬度（纬度与经度用逗号分隔）
    * */

    @ApiOperation(value = "区域查车（只能矩形）接口")
    @RequestMapping(value = "/getVehicleByArea",method = RequestMethod.GET)
    public JSONObject getVehicleByArea(String startTime,String endTime,String leftUpPosition,String rightDownPosition){
      Map map=new HashMap();
      map.put("startTime",startTime);// 开始时间 yyyy-mm-dd HH:mm:ss
      map.put("endTime",endTime);// 结束时间  yyyy-mm-dd HH:mm:ss
      map.put("leftUpPosition",leftUpPosition);//必传 左上角经纬度(纬度与经度用逗号分隔)
      map.put("rightDownPosition",rightDownPosition);//必传 右下角经纬度（纬度与经度用逗号分隔）
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
      String url="http://"+Ip+":"+port+"/dis/v1/organization/getVehicleByArea";
      String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("data");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer eId=Integer.parseInt(jsonObject.getString("eid"));//企业id
            String vehicelColor=jsonObject.getString("vcolor");//车辆颜色
            Integer vId= Integer.valueOf(jsonObject.getString("vid"));//车辆id
            String industryName=tDisVehicleMapper.selectIndustryName(vId);
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);//企业名称
            String vehicleLicenseColor=disDictionaryMapper.selectVehicleColor(vehicelColor);//车牌颜色
            jsonObject.put("vehicleLicenseColor",vehicleLicenseColor);
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("industryName",industryName);
        };
        return json;
    }



    @ApiOperation(value = "查询区域的实时入网率、上线率")
    @RequestMapping(value = "/realtimeRate",method = RequestMethod.GET)
    public JSONObject realtimeRate(String regionCode,String industryIds){
      Map map=new HashMap();
      map.put("regionCode",regionCode);//必传 登录用户所属的行政区划代码
        map.put("industryIds",industryIds);//行业类别，多个以逗号分隔
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/organization/realtimeRate";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("result");
        JSONObject js=jsonArray.getJSONObject(0);
        //最大入网率
        Double maxNetwork=Double.valueOf(js.getString("networkVehicleRate").replace("%",""));
        //最小上线率
        Double maxOnline=Double.valueOf(js.getString("monthNetworkVehicleRate").replace("%",""));
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            String networkVehicleRate=jsonObject.getString("networkVehicleRate");//入网率
            String monthNetworkVehicleRate=jsonObject.getString("monthNetworkVehicleRate");//上线率
            String networkVehicle=networkVehicleRate.replace("%","");
            String monthNetworkVehicle=monthNetworkVehicleRate.replace("%","");
            //三目运算 计算最大入网率
            maxNetwork=(Double.valueOf(networkVehicle)< maxNetwork?maxNetwork: Double.valueOf(networkVehicle));
            //三目运算 计算最大上线率
            maxOnline=(Double.valueOf(monthNetworkVehicle)< maxOnline?maxOnline: Double.valueOf(monthNetworkVehicle));
            jsonObject.put("networkVehicle",networkVehicle);
            jsonObject.put("monthNetworkVehicle",monthNetworkVehicle);
        }


        //最小入网率
        Double minNetwork=Double.valueOf(js.getString("networkVehicleRate").replace("%",""));
        //最小上线率
        Double minOnline=Double.valueOf(js.getString("networkVehicleRate").replace("%",""));

        for (int i = 0; i <jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            String networkVehicleRate=jsonObject.getString("networkVehicleRate");//入网率
            String monthNetworkVehicleRate=jsonObject.getString("monthNetworkVehicleRate");//上线率
            String networkVehicle=networkVehicleRate.replace("%","");
            String monthNetworkVehicle=monthNetworkVehicleRate.replace("%","");
            //三目运算 计算最小入网率
            minNetwork=(Double.valueOf(networkVehicle)> minNetwork?minNetwork:Double.valueOf(networkVehicle));
            //三目运算 计算最小上线率
            minOnline=(Double.valueOf(monthNetworkVehicle)> minOnline?minOnline:Double.valueOf(monthNetworkVehicle));
        }
        json.put("maxNetworkvehicle",maxNetwork);
        json.put("maxOnlinevehicle",maxOnline);
        json.put("minNetworkvehicle",minNetwork);
        json.put("minOnlinevehicle",minOnline);
        return json;
    }

}
